// Win32 utility functions
// Copyright 2006 (C) Ralph Thomas

#include <toolkit/win32/util-win32.h>
#include <windows.h>
#include <vector>

namespace toolkit {
	std::wstring convert_utf( const std::string& in )
	{
		typedef		std::vector<WCHAR> buftype;
		int			length = MultiByteToWideChar(CP_UTF8, 0, in.c_str(), static_cast<int>(in.size()), 0, 0);
		buftype		tmpbuf(length + 1);
		//
		// Convert characters.
		//
		MultiByteToWideChar(CP_UTF8, 0, in.c_str(), static_cast<int>(in.size()), &(tmpbuf[0]), length);
		return std::wstring(&(tmpbuf[0]));
	}
	std::string convert_utf( const std::wstring& in ) {
		typedef		std::vector<char> buftype;
		int			length = WideCharToMultiByte(CP_UTF8, 0, in.c_str(), static_cast<int>(in.size()), 0, 0, 0, 0);
		buftype		tmpbuf(length + 1);
		//
		// Convert characters.
		//
		WideCharToMultiByte(CP_UTF8, 0, in.c_str(), static_cast<int>(in.size()), &(tmpbuf[0]), length, 0, 0);
		return std::string(&(tmpbuf[0]));
	}
}
